package com.liuzh.kaoyanspringboot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.liuzh.kaoyanspringboot.common.Constants;
import com.liuzh.kaoyanspringboot.entity.Article;
import com.liuzh.kaoyanspringboot.entity.Comment;
import com.liuzh.kaoyanspringboot.entity.Concern;
import com.liuzh.kaoyanspringboot.entity.User;
import com.liuzh.kaoyanspringboot.mapper.ConcernMapper;
import com.liuzh.kaoyanspringboot.service.ConcernService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liuzh.kaoyanspringboot.service.MessageService;
import com.liuzh.kaoyanspringboot.service.UserService;
import com.liuzh.kaoyanspringboot.utils.TokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 刘志鸿
 * @since 2023-04-11
 */
@Service
public class ConcernServiceImpl extends ServiceImpl<ConcernMapper, Concern> implements ConcernService {

    @Resource
    private ConcernMapper concernMapper;
    @Autowired
    private MessageService messageService;
    @Autowired
    private UserService userService;

    @Override
    public List<User> getUsersByMyId(Integer myId) {
        return concernMapper.getUsersByMyId(myId);
    }


    @Override
    public boolean removeConcern(Integer myId, Integer concernId) {
        return concernMapper.deleteConcern(myId,concernId);
    }

    @Override
    public boolean findConcern(Integer concernId, Integer myId) {
        return concernMapper.isConcern(myId, concernId);
    }

    @Override
    public List<Article> findConcernArticle(Integer userId) {
        return concernMapper.findConcernArticle(userId);
    }

    @Override
    public Boolean mySave(Concern concern) {
        messageService.createAndSave(concern.getConcernId(),concern.getMyId(), Constants.TYPE_CONCERN,null,"");
        return save(concern);
    }

}
